package all.com.jinyongqunxiax.model.mod;


import com.randy.fundation.JxAssert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import all.com.jinyongqunxiax.BuildConfig;
import androidx.annotation.NonNull;
import jy.game.components.role.JyRoleGrowTemplate;
import jy.game.tools.BasePojoManager;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.ElementList;

public class GrowManager {
    public Map<String, JyRoleGrowTemplate> map  = new HashMap<>();
    public List<JyRoleGrowTemplate>        list = new ArrayList<>();
    String xmlPath;

    public GrowManager(@NonNull String xmlPath) {
        this.xmlPath = xmlPath;
    }

    BasePojoManager<JyRoleGrowTemplate> manager;

    public String load() {
        map.clear();
        list.clear();

        manager = BasePojoManager.build(xmlPath, JyRoleGrowTemplate.class);
        list = manager.datas;
        if (!manager.success()) {
            return manager.message;
        }
        StringBuilder message = new StringBuilder(getClass().getSimpleName());

        for (JyRoleGrowTemplate item : list) {
            if (map.containsKey(item.name)) {
                message.append("发现重复:").append(item.name);
                continue;
            }
            map.put(item.name, item);
        }


        return manager.message;
    }

//    static public class Root {
//        @ElementList(inline = true) List<Model> models;
//    }
//
//    /**
//     * <grow_template bili="1" daofa="1" dingli="1" fuyuan="1" gengu="1" hp="1440" jianfa="1" mp="960" name="default" qimen="1" quanzhang="1" shenfa="1" wuxing="0" wuxue="16"/>
//     */
//    @wx.xml.simpleframework.xml.Root(name = "grow_template")
//    static public class Model {
//        public @Attribute String name;
//
//        public @Attribute int wuxue;
//
//        public @Attribute int hp;
//        public @Attribute int mp;
//
//        public @Attribute int quanzhang;
//        public @Attribute int jianfa;
//        public @Attribute int daofa;
//        public @Attribute int qimen;
//
//        public @Attribute int bili;
//        public @Attribute int dingli;
//        public @Attribute int fuyuan;
//        public @Attribute int gengu;
//        public @Attribute int shenfa;
//        public @Attribute int wuxing;
//    }
}
